

/***********************************************************************/
/* INCLUDE FILE NAME:  det_ui.h                                        */
/* ==================                                                  */
/*                                                                     */
/* Author:  John DeGood                                                */
/*                                                                     */
/* COMMENT: Include file for detector user interface functions.        */
/*                                                                     */
/***********************************************************************/

#ifndef DET_UI_H
#define DET_UI_H

/*****************************/
/*   IFDEFS                  */
/*****************************/

/*****************************/
/*   SYMBOLIC CONSTANTS      */
/*****************************/

/* The 8-bit ECD DAC outputs 0-10V to a 2 gigaohm resistor offset by -0.798 volts.
 * Therefore:
 *
 *      DAC_setpt = reference_current * 2 * 255
 *                  ---------------------------
 *                             10.798
 *
 *      reference_current is in nA
 */
#define ECD_DAC_MIN                     24              /* DAC setpt = 0.5 nA */
#define ECD_DAC_MAX                     255             /* DAC setpt = FS */

#define ECD_REF_CURRENT_MIN             50              /* 0.01 nA */
#define ECD_REF_CURRENT_DEFAULT         100             /* 0.01 nA */
#define ECD_REF_CURRENT_MAX             540             /* 0.01 nA */

#define ECD_TARGET_MIN                  (100/5)         /* 5 Hz */
#define ECD_TARGET_DEFAULT              (300/5)         /* 5 Hz */
#define ECD_TARGET_MAX                  (1000/5)        /* 5 Hz */

#define NPD_BEAD_POWER_MIN              0               /* mV (DAC setpt = 0) */
#define NPD_BEAD_POWER_DEFAULT          2500            /* mV */
#define NPD_BEAD_POWER_MAX              4095            /* mV (DAC setpt = FS) */
#define NPD_MAX_1SEC_CHG        13      /* MAX mv increase in 1.0 sec time step */

#define NPD_TARGET_MIN                  10              /* pA */
#define NPD_TARGET_DEFAULT              30              /* pA */
#define NPD_TARGET_MAX                  99              /* pA */

#define NPD_EQUIB_TIME_DEFAULT          (5*100)         /* 0.01 minutes */

#define FID_LIT_OFFSET_MIN              0               /* 0.1 pA */
#define FID_LIT_OFFSET_DEFAULT          20              /* 0.1 pA */
#define FID_LIT_OFFSET_MAX              999             /* 0.1 pA */

#define FPD_LIT_OFFSET_MIN              0               /* units 150 pA */
#define FPD_LIT_OFFSET_DEFAULT          20              /* units 150 pA */
#define FPD_LIT_OFFSET_MAX              999             /* units 150 pA */

/**** CPF defines ****/
#define FRMT_NUMERIC            0        /* CPF's OIM control format */
#define FRMT_ON_OFF             1        /* CPF's OIM control format */

#define RTT_CPF_CTL_ON     ((INT32)-1)   /* RTT - indicates set control on */
#define RTT_CPF_CTL_OFF    ((INT32)-2)   /* RTT - indicates set control off */


/*****************************/
/*   MACROS                  */
/*****************************/

/*****************************/
/*   TYPEDEFS                */
/*****************************/

/*****************************/
/*   FUNCTION PROTOTYPES     */
/*****************************/

/************/
/* det_ui.c */
/************/

/* Generic detector functions */
DET_TYPE GetDetectorType(POSITION p);
INT32    GetDetectorOffset(POSITION p);
BIT8     *GetDetSignalLabel(POSITION p);
UI_ERR   SetDetSignalLabel(POSITION p, BIT8 *label);
void     ClearDetSignalLabel(POSITION p);
void     InitDetSignalLabel( POSITION position );

ON_OFF GetDetDiagLinearMode(POSITION p);
UI_ERR SetDetDiagLinearMode(POSITION p, ON_OFF on_off);

INT16 DetectorIsOn(POSITION p);

ON_OFF GetDetOnOff (POSITION p);
ON_OFF GetDetInput0(POSITION p);
ON_OFF GetDetInput1(POSITION p);
ON_OFF GetDetInput2(POSITION p);
ON_OFF GetDetInput3(POSITION p);
ON_OFF GetDetInput4(POSITION p);
ON_OFF GetDetInput5(POSITION p);

void SetDetOnOff (POSITION p, ON_OFF on_off);
void SetDetInput0(POSITION p, ON_OFF on_off);
void SetDetInput1(POSITION p, ON_OFF on_off);
void SetDetInput2(POSITION p, ON_OFF on_off);
void SetDetInput3(POSITION p, ON_OFF on_off);
void SetDetInput4(POSITION p, ON_OFF on_off);
void SetDetInput5(POSITION p, ON_OFF on_off);

void SetDetDiagInput0(POSITION p, ON_OFF on_off);
void SetDetDiagInput1(POSITION p, ON_OFF on_off);
void SetDetDiagInput2(POSITION p, ON_OFF on_off);
void SetDetDiagInput3(POSITION p, ON_OFF on_off);

UI_ERR SetDetSetptOnOff(POSITION p, ON_OFF on_off);

U_INT16 GetDetVOut1(POSITION p);
U_INT16 GetDetVOut2(POSITION p);

INT32  GetDetEquibTime(POSITION p);
UI_ERR SetDetEquibTime(POSITION p, INT32 deciminutes);

ON_OFF GetFlame(POSITION p);
UI_ERR SetFlame(POSITION p, ON_OFF on_off);
UI_ERR DCSetFlame(POSITION p, ON_OFF on_off);

/* FID functions */
INT32  GetFIDLitOffset(POSITION p);
UI_ERR SetFIDLitOffset(POSITION p, INT32 pA_x_10);

/* FPD functions */
INT32  GetFPDLitOffset(POSITION p);
UI_ERR SetFPDLitOffset(POSITION p, INT32 pA_x_10);

/* TCD functions */
ON_OFF GetTCDFilament(POSITION p);
UI_ERR SetTCDFilament(POSITION p, ON_OFF on_off);
UI_ERR DCSetTCDFilament(POSITION p, ON_OFF on_off);
ON_OFF GetTCDNegPolarity(POSITION p);
UI_ERR SetTCDNegPolarity(POSITION p, ON_OFF on_off);

/* ECD functions */
INT32 ECDRefCurrentToDAC(INT32 value);
INT32 ECDDACToRefCurrent(INT32 value);
INT32 GetECDDAC(POSITION p);
UI_ERR SetECDDAC(POSITION p, INT32 value);
INT32 GetECDRefCurrent(POSITION p);
UI_ERR SetECDRefCurrent(POSITION p, INT32 value);
INT32 GetECDTargetOffset(POSITION p);
UI_ERR SetECDTargetOffset(POSITION p, INT32 value);
UI_ERR StartECDOffsetSeek(POSITION p);
UI_ERR StopECDOffsetSeek(POSITION p);
ON_OFF GetECDStatus(POSITION p);

/* LDID Functions */
INT32  GetLDIDGlowStatus (POSITION p);
INT32  GetLDIDGlowLevel  (POSITION p);
ON_OFF GetLDIDGlowSetpt  (POSITION p);
UI_ERR SetLDIDGlowSetpt  (POSITION p, ON_OFF on_off);
UI_ERR SetLDIDSetptOnOff (POSITION p, ON_OFF on_off);
ON_OFF GetLDIDOnOff      (POSITION p);
ON_OFF GetLDIDElecOnOff  (POSITION p);
UI_ERR SetLDIDElecOnOff  (POSITION p, ON_OFF on_off);

/* NPD functions */
INT32 GetNPDDebugIndex(void);
UI_ERR SetNPDDebugIndex(INT32 value);
INT32 GetNPDDebugParam(void);
UI_ERR SetNPDDebugParam(INT32 value);
ON_OFF GetNPDBeadTurnOn(POSITION p);
UI_ERR SetNPDBeadTurnOn(POSITION p, ON_OFF on_off);
UI_ERR DCSetNPDBeadTurnOn(POSITION p, ON_OFF on_off);
INT32 GetNPDTargetOffset(POSITION p);
UI_ERR SetNPDTargetOffset(POSITION p, INT32 pA);
UI_ERR StartNPDOffsetSeek(POSITION p);
UI_ERR StopNPDOffsetSeek(POSITION p);
INT32 GetNPDBeadVoltage(POSITION p);
INT32 GetNPDBeadDACVolts(POSITION p);
UI_ERR SetNPDBeadVoltage(POSITION p, INT32 value);

/* AIB, Electrometer functions */

void   CheckForDetPneuElecMismatches( void );

BIT8   ManualElectrometer( POSITION p );
BIT8   GetElectrometerType( POSITION p );
UI_ERR SetElectrometerType( POSITION p, BIT8 electrometer );
UI_ERR SetElectrometerTitle(POSITION p, BIT8 *title);
void InstallElectrometerTitle(POSITION p);
void ClearElectrometerTitle(POSITION p);

/**** DEBUG *** DEBUG *** DEBUG *** DEBUG *** DEBUG *** DEBUG *** DEBUG ****/

/*** This is ONLY for TCD debug with a special version of Bob Rhodes DSP code ***/
/* uncomment the following line to activate the TCD debug code */
/* #define DEBUG_TCD_SKEW */

#ifdef DEBUG_TCD_SKEW

INT32 GetTCDStart1(void);
INT32 GetTCDStart2(void);
INT32 GetTCDStop1(void);
INT32 GetTCDStop2(void);
UI_ERR SetTCDStart1(INT32 value);
UI_ERR SetTCDStart2(INT32 value);
UI_ERR SetTCDStop1(INT32 value);
UI_ERR SetTCDStop2(INT32 value);

#endif /* DEBUG_TCD_SKEW */

/**** DEBUG *** DEBUG *** DEBUG *** DEBUG *** DEBUG *** DEBUG *** DEBUG ****/

/*************/
/* cpf_det.c */
/*************/

/**** CPF prototypes ****/

BIT8    GetCPFDetPneuPresence( POSITION position );
BIT8    GetCPFDetTitlePresence( POSITION position );
BIT8    GetCPFDetGasPresence( POSITION position, BIT8 gas_num );
BIT8    GetCPFCtlPresence( POSITION position, BIT8 channel );
BIT8    GetOEMCtlPresence( POSITION position, BIT8 channel );
BIT8    GetCPFOIMPresence( POSITION position );
BIT8   *GetCPFDetTitle( POSITION position );
BIT8   *GetCPFGasLabel( POSITION position, BIT8 gas_num );
BIT8   *GetCPFCtlLabel( POSITION position, BIT8 channel );
BIT8   *GetOEMCtlLabel( POSITION position, BIT8 channel );
BIT8   *GetDetGasLabel( POSITION pos, BIT8 gas );
BIT8    GetCPFCtlFormat( POSITION position, BIT8 channel );
BIT8    GetCPFCtlNumBits( POSITION position, BIT8 channel );
INT32   MinCPFCtlValue( POSITION position, BIT8 channel );
INT32   MaxCPFCtlValue( POSITION position, BIT8 channel );
UI_ERR  CheckCPFCtlOnOff( POSITION position, BIT8 channel, ON_OFF value );
UI_ERR  CheckCPFCtlValue( POSITION position, BIT8 channel, INT32 value );
UI_ERR  CheckOEMCtlOnOff( POSITION position, BIT8 channel, ON_OFF value );
UI_ERR  CheckOEMXtlValue( POSITION position, INT32 value );
ON_OFF  GetCPFCtlOnOff( POSITION position, BIT8 channel );
ON_OFF  GetOEMOnOffActual( POSITION position, BIT8 channel );
ON_OFF  GetOEMCtlOnOff( POSITION position, BIT8 channel );
U_INT16 GetCPFCtlValue( POSITION position, BIT8 channel );
UI_ERR  SetCPFCtlOnOff( POSITION position, BIT8 channel, ON_OFF value );
UI_ERR  SetCPFCtlValue( POSITION position, BIT8 channel, INT32 value );
void    CPFCtlBdOnOff( POSITION position, ON_OFF on_off );
void    UpdateCPFCtlValues (void);
void    InitCPFOIMPresence (POSITION position);
void    CheckCPFDetConfigInWkfile(void);
void    RTTSetCPFCtlFrnt1(INT32 value);
void    RTTSetCPFCtlFrnt2(INT32 value);
void    RTTSetCPFCtlFrnt3(INT32 value);
void    RTTSetCPFCtlFrnt4(INT32 value);
void    RTTSetOEMCtlFrnt5(INT32 value);
void    RTTSetOEMCtlFrnt7(INT32 value);
void    RTTSetCPFCtlBack1(INT32 value);
void    RTTSetCPFCtlBack2(INT32 value);
void    RTTSetCPFCtlBack3(INT32 value);
void    RTTSetCPFCtlBack4(INT32 value);
void    RTTSetOEMCtlBack5(INT32 value);
void    RTTSetOEMCtlBack7(INT32 value);
BIT8    GetCPFDetUnitsLabelPresence( POSITION position );
BIT8    *GetCPFDetUnitsLabel( POSITION position );

OEM_GAS_STATUS  GetOEMGasStatus( pDETECTOR_STATUS status, BIT8 gas );
BIT8            GetOEMCtlPulseLen( POSITION position, BIT8 channel );
void            SetOEMDetInput(POSITION p, ON_OFF on_off, BIT8 channl );
UI_ERR          SetOEMXtrlValue( POSITION position,  INT32 value );
UI_ERR          SetOEMCtlOnOff( POSITION position, BIT8 channel, ON_OFF value );
INT32           GetOEMDiagValu ( POSITION pos, BIT8 ch );
void            CheckOEMDetConfigInWkfile(void);
void            RestoreOEMControls (POSITION p);

#endif
